// $ANTLR 2.7.6 (2005-12-22): "objectExpression.g" -> "ObjectExpression.java"$

package com.aote.expression.antlr;

import antlr.TokenBuffer;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.ANTLRException;
import antlr.LLkParser;
import antlr.Token;
import antlr.TokenStream;
import antlr.RecognitionException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.ParserSharedInputState;
import antlr.collections.impl.BitSet;

public class ObjectExpression extends antlr.LLkParser       implements ObjectExpressionTokenTypes
 {

	private static final byte GE=0;
	private static final byte GT=1;
	private static final byte LE=2;
	private static final byte LT=3;
	private static final byte EQ=4;
	private static final byte NE=5;
	
	private boolean compare(String str1, String str2, byte op) {
		int result = str1.compareTo(str2);
		switch(op) {
			case GE:
				return result >= 0; 
			case GT:
				return result > 0;
			case LE:
				return result <= 0;
			case LT:
				return result < 0;
			case EQ:
				return result == 0;
			case NE:
				return result != 0;
		}
		return false;
	}

protected ObjectExpression(TokenBuffer tokenBuf, int k) {
  super(tokenBuf,k);
  tokenNames = _tokenNames;
}

public ObjectExpression(TokenBuffer tokenBuf) {
  this(tokenBuf,1);
}

protected ObjectExpression(TokenStream lexer, int k) {
  super(lexer,k);
  tokenNames = _tokenNames;
}

public ObjectExpression(TokenStream lexer) {
  this(lexer,1);
}

public ObjectExpression(ParserSharedInputState state) {
  super(state,1);
  tokenNames = _tokenNames;
}

	public final String  expression() throws RecognitionException, TokenStreamException {
		String result=null;
		
		
		try {      // for error handling
			expressionItem();
			{
			_loop3:
			do {
				if ((LA(1)==ADD)) {
					match(ADD);
					expressionItem();
				}
				else {
					break _loop3;
				}
				
			} while (true);
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_0);
		}
		return result;
	}
	
	public final String  expressionItem() throws RecognitionException, TokenStreamException {
		String result=null;
		
		
		try {      // for error handling
			switch ( LA(1)) {
			case ID:
			{
				objectPathItem();
				break;
			}
			case STRING:
			{
				match(STRING);
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_1);
		}
		return result;
	}
	
	public final String  objectPathItem() throws RecognitionException, TokenStreamException {
		String result=null;
		
		
		try {      // for error handling
			objectItem();
			{
			_loop7:
			do {
				if ((LA(1)==DOT)) {
					match(DOT);
					objectItem();
				}
				else {
					break _loop7;
				}
				
			} while (true);
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_1);
		}
		return result;
	}
	
	public final Object  objectItem() throws RecognitionException, TokenStreamException {
		Object result=null;
		
		
		try {      // for error handling
			match(ID);
			{
			_loop10:
			do {
				if ((LA(1)==MLEFT)) {
					match(MLEFT);
					condition();
					match(MRIGHT);
				}
				else {
					break _loop10;
				}
				
			} while (true);
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		}
		return result;
	}
	
	public final boolean  condition() throws RecognitionException, TokenStreamException {
		boolean result=false;
		
		Token  b = null;
		
			String e1, e2;
			byte op;
		
		
		try {      // for error handling
			if ((LA(1)==STRING||LA(1)==ID)) {
				e1=expression();
				{
				switch ( LA(1)) {
				case GR:
				case LT:
				case GE:
				case LE:
				case EQ:
				case NE:
				{
					op=operator();
					e2=expression();
					result=compare(e1, e2, op);
					break;
				}
				case BETWEEN:
				{
					b = LT(1);
					match(BETWEEN);
					System.out.println(b.getText());
					match(LEFT);
					expression();
					match(COMMA);
					expression();
					match(RIGHT);
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				}
				}
			}
			else if ((LA(1)==ID)) {
				objectItem();
			}
			else {
				throw new NoViableAltException(LT(1), getFilename());
			}
			
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_3);
		}
		return result;
	}
	
	public final byte  operator() throws RecognitionException, TokenStreamException {
		byte result=0;
		
		
		try {      // for error handling
			switch ( LA(1)) {
			case GR:
			{
				match(GR);
				result=GR;
				break;
			}
			case LT:
			{
				match(LT);
				result=LT;
				break;
			}
			case GE:
			{
				match(GE);
				result=GE;
				break;
			}
			case LE:
			{
				match(LE);
				result=LE;
				break;
			}
			case EQ:
			{
				match(EQ);
				result=EQ;
				break;
			}
			case NE:
			{
				match(NE);
				result=NE;
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_4);
		}
		return result;
	}
	
	
	public static final String[] _tokenNames = {
		"<0>",
		"EOF",
		"<2>",
		"NULL_TREE_LOOKAHEAD",
		"ADD",
		"STRING",
		"DOT",
		"ID",
		"MLEFT",
		"MRIGHT",
		"BETWEEN",
		"LEFT",
		"COMMA",
		"RIGHT",
		"GR",
		"LT",
		"GE",
		"LE",
		"EQ",
		"NE",
		"GT"
	};
	
	private static final long[] mk_tokenSet_0() {
		long[] data = { 1046016L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
	private static final long[] mk_tokenSet_1() {
		long[] data = { 1046032L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
	private static final long[] mk_tokenSet_2() {
		long[] data = { 1046096L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
	private static final long[] mk_tokenSet_3() {
		long[] data = { 512L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3());
	private static final long[] mk_tokenSet_4() {
		long[] data = { 160L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_4 = new BitSet(mk_tokenSet_4());
	
	}
